package Service.src;

import Data.src.Pokemon; // 导入Pokemon类

import java.util.Random;

public class Attack {
    public static void main(String[] args) {
        // 创建宠物对象数组
        Pokemon[] pets = new Pokemon[14]; // 存储宠物实例的数组

        // 初始化宠物对象
        pets[0] = new Pokemon("皮卡丘", 1001, 1, 66, 66, "");
        pets[1] = new Pokemon("小火龙", 1002, 1, 70, 50, "");
        pets[2] = new Pokemon("妙蛙花", 1003, 1, 60, 60, "");
        pets[3] = new Pokemon("杰尼龟", 1004, 1, 40, 80, "");
        pets[4] = new Pokemon("杰尼龟", 1005, 1, 40, 80, "");
        pets[5] = new Pokemon("杰尼龟", 1006, 1, 40, 80, "");
        pets[6] = new Pokemon("杰尼龟", 1007, 1, 40, 80, "");
        pets[7] = new Pokemon("杰尼龟", 1008, 1, 40, 80, "");
        pets[8] = new Pokemon("杰尼龟", 1009, 1, 40, 80, "");
        pets[9] = new Pokemon("杰尼龟", 1010, 1, 40, 80, "");
        pets[10] = new Pokemon("杰尼龟", 1011, 1, 40, 80, "");
        pets[11] = new Pokemon("杰尼龟", 1012, 1, 40, 80, "");
        pets[12] = new Pokemon("杰尼龟", 1013, 1, 40, 80, "");
        pets[13] = new Pokemon("杰尼龟", 1014, 1, 40, 80, "");

        Random rand = new Random();

        Pokemon firstPet = pets[0]; // 获取第一个宠物

        // 第一个宠物与其他所有宠物依次进行战斗
        for (int i = 1; i < pets.length; i++) {
            Pokemon enemy = pets[i];

            // 进行一次战斗
            while (isAlive(firstPet) && isAlive(enemy)) {
                // 第一个宠物攻击敌人
                attack(firstPet, enemy);
                if (!isAlive(enemy)) {
                    System.out.println(firstPet.getName() + " 获胜！");
                    break;
                }

                // 敌人攻击第一个宠物
                attack(enemy, firstPet);
                if (!isAlive(firstPet)) {
                    System.out.println(enemy.getName() + " 获胜！");
                    break;
                }

                // 有一定概率进行回血
                if (rand.nextDouble() < 0.5) { // 假设回血的概率为50%
                    heal(firstPet); // 调用回血方法
                }
            }
        }
    }

    // 判断宠物是否存活
    private static boolean isAlive(Pokemon pokemon) {
        return pokemon.getHP() > 0;
    }

    // 宠物攻击方法
    private static void attack(Pokemon attacker, Pokemon target) {
        int damage = attacker.getAtk();
        target.setHP(target.getHP() - damage);
        System.out.println(attacker.getName() + " 攻击！对敌人造成了 " + damage + " 点伤害！");
    }

    // 宠物回血方法
    private static void heal(Pokemon pokemon) {
        // 假设每次回血 20 点
        int healAmount = 20;
        pokemon.setHP(pokemon.getHP() + healAmount);
        System.out.println(pokemon.getName() + " 回血！生命值增加了 " + healAmount + " 点！");
    }
}

